// miniprogram/pages/house/house.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    flag: true,
    clist: [{
        name: '丹东',
        city: 'dd'
      },
      {
        name: '庄河',
        city: 'zhuanghe'
      },
      {
        name: '淮安',
        city: 'huaian'
      },
      {
        name: '沈阳',
        city: 'sy'
      },
      {
        name: '廊坊',
        city: 'lf'
      },
      {
        name: '威海',
        city: 'weihai'
      },
      {
        name: '青岛',
        city: 'qd'
      },
      {
        name: '滨州',
        city: 'binzhou'
      },
      {
        name: '长春',
        city: 'cc'
      },
      {
        name: '眉山',
        city: 'meishan'
      },
      {
        name: '大连',
        city: 'dl'
      },
      {
        name: '上海',
        city: 'sh'
      },
      {
        name: '湛江',
        city: 'zj'
      },
      {
        name: '石家庄',
        city: 'sjz'
      },
      {
        name: '柳州',
        city: 'liuzhou'
      },
      {
        name: '呼和浩特',
        city: 'nm'
      },
      {
        name: '天津',
        city: 'tj'
      },
      {
        name: '清远',
        city: 'qingyuan'
      },
      {
        name: '杭州',
        city: 'hz'
      },
    ],
    tlist: [{
        type: 1,
        name: '新房'
      },
      {
        type: 2,
        name: '二手房'
      },
      {
        type: 3,
        name: '出租房'
      },
    ],
    hlist: [{
        name: '全部'
      },
      {
        name: '普通'
      },
      {
        name: '别墅'
      },
      {
        name: '海景房'
      },
    ],
    flag1:true,
    flag2: true,
    flag3: true,
    city:'hz',
    c_name:'杭州',
    t_name:'新房',
    type:1,
    name:'全部'
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    this.getHouseInfo();
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {

  },
  getHouseInfo() {
    let _this = this;
    let city=this.data.city;
    let type = this.data.type;
    let name = this.data.name;
    wx.cloud.callFunction({
      name: 'getHouseInfo',
      data:{
        city:city,
        type:type,
        name:name
      },
      success: res => {
        console.log(res)
        _this.setData({
          hinfo: res.result.data,
        })
      },
      fail: err => {
        console.log(err)
      }
    })
  },
  getDetailInfo(e) {
    let idx = e.currentTarget.dataset.idx;
    let hinfo = this.data.hinfo;
    this.setData({
      dinfo: hinfo[idx],
      flag: false,
    })
  },
  hideDetail() {
    this.setData({
      flag: true
    })
  },
  getCity(){
    this.setData({
      flag1:false
    })
  },
  getHouseOrig(){
    this.setData({
      flag2: false
    })
  },
  getHouseType(){
    this.setData({
      flag3: false
    })
  },
  getCityId(e){
    let city=e.currentTarget.dataset.city;
    let cname = e.currentTarget.dataset.cname;
    this.setData({
       city:city,
       c_name:cname,
       flag1:true,
    })
  },
  getCityOrig(e){
    let type = e.currentTarget.dataset.type;
    let tname = e.currentTarget.dataset.tname;
    this.setData({
      type:type,
      t_name:tname,
      flag2: true,
    })
  },
  getCityType(e){
    let name = e.currentTarget.dataset.name;
    this.setData({
      name:name,
      flag3: true,
    })
    console.log('开始执行');
    this.getHouseInfo();
  },
  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function() {

  }
})